﻿using System;
using System.Collections.Generic;
using System.Text;


using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;
using DevExpress.Xpo;
using DevExpress.Xpo.Metadata;
using OT.Module.ModelConst;
using OT.Common;
using OT.EntLib.Validate;


namespace OT.Module.Model
{
    [Persistent(GDB.OrderDetail)]
    public partial class OrderDetail : XPLiteObject
    {
        #region ~

        /// <summary>
        /// 构造函数
        /// </summary>
        public OrderDetail() : base ( new Session() )
        {

        }

        public OrderDetail(Session s)
            : base(s)
        {
        }

        public OrderDetail(Session s, XPClassInfo info)
            : base(s, info)
        {
        }

        #endregion

        #region ID

        private string _ID = "";
        /// <summary>
        /// 
        /// </summary>
        [Key(false)]
        public string ID
        {
            get
            {
                return _ID;
            }
            set
            {
                SetPropertyValue("ID", ref _ID, value);
            }
        }
        #endregion

        #region BelongOrder  所属订单

        private Order _BelongOrder;

        [Association("Order-OrderDetails")]
        public Order BelongOrder
        {
            get
            {
                return _BelongOrder;
            }
            set
            {
                SetPropertyValue("BelongOrder", ref _BelongOrder, value);
            }
        }

        #endregion

        #region ProductName 产品名称

        private string _ProductName;

        [StringLengthValidator(GConst.NameMinLen, GConst.NameMaxLen,
          MessageTemplate = MsgUtility.StringLength, Tag = GSyntax.OrderDetail.ProductName)]
        [DisplayName(GSyntax.OrderDetail.ProductName), Size(GConst.NameMaxLen)]
        public string ProductName
        {
            get { return _ProductName; }
            set { SetPropertyValue("ProductName", ref _ProductName, value); }
        }

        #endregion

        #region SalePrice 销售价格

        private decimal _SalePrice;

        [DisplayName(GSyntax.OrderDetail.SalePrice)]
        public decimal SalePrice
        {
            get { return _SalePrice; }
            set { SetPropertyValue("SalePrice", ref _SalePrice, value); }
        }

        #endregion

        #region SaleNum 销售数量

        private int _SaleNum;
        [RangeValidator(0, RangeBoundaryType.Exclusive, Int32.MaxValue, RangeBoundaryType.Inclusive,
            MessageTemplate = MsgUtility.IntRangeGreaterBetween, Tag = GSyntax.OrderDetail.SaleNum)]
        [DisplayName(GSyntax.OrderDetail.SaleNum)]
        public int SaleNum
        {
            get { return _SaleNum; }
            set { SetPropertyValue("SaleNum", ref _SaleNum, value); }
        }

        #endregion

        #region TotalPrice 合计价格

        [PersistentAlias("SalePrice*SaleNum")]
        [DisplayName(GSyntax.OrderDetail.TotalPrice)]
        public decimal TotalPrice
        {
            get { return Convert.ToDecimal(EvaluateAlias("TotalPrice")); }
        }

        #endregion

    }
}
